{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Crossfilter\n",
    "===========\n",
    "This example shows a multi-panel view of the same data, where you can interactively\n",
    "select a portion of the data in any of the panels to highlight that portion in any\n",
    "of the other panels.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# category: interactive\n",
    "\n",
    "import altair as alt\n",
    "alt.data_transformers.enable('json')\n",
    "from vega_datasets import data\n",
    "\n",
    "flights = alt.UrlData(data.flights_2k.url,\n",
    "                      format={'parse': {'date': 'date'}})\n",
    "\n",
    "brush = alt.selection(type='interval', encodings=['x'])\n",
    "\n",
    "# Define the base chart, with the common parts of the\n",
    "# background and highlights\n",
    "base = alt.Chart().mark_bar().encode(\n",
    "    x=alt.X(alt.repeat('column'), type='quantitative', bin=alt.Bin(maxbins=20)),\n",
    "    y='count()'\n",
    ").properties(\n",
    "    width=180,\n",
    "    height=130\n",
    ")\n",
    "\n",
    "# blue background with selection\n",
    "background = base.properties(\n",
    "    selection=brush\n",
    ")\n",
    "\n",
    "# yellow highlights on the transformed data\n",
    "highlight = base.encode(\n",
    "    color=alt.value('goldenrod')\n",
    ").transform_filter(\n",
    "    brush.ref()\n",
    ")\n",
    "\n",
    "# layer the two charts & repeat\n",
    "alt.layer(\n",
    "    background, highlight,\n",
    "    data=flights\n",
    ").transform_calculate(\n",
    "    \"time\", \"hours(datum.date)\"\n",
    ").repeat(\n",
    "    column=[\"distance\", \"delay\", \"time\"]\n",
    ")\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "env": {},
   "interrupt_mode": "signal",
   "language": "python",
   "metadata": {},
   "name": "python3"
  },
  "language": "python"
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
